﻿using B.S.BaseData.Api.Write.Applicantion.Command.GoodsCommand;
using B.S.BaseData.ErrorCode;
using B.S.BaseData.Infrastructure.Interface;
using B.S.BataBase.Domain.Entitys;
using MediatR;

namespace B.S.BaseData.Api.Write.Applicantion.CommandHandler.GoodsCommandHandler
{
    public class GoodsvendoradditiveUpdateCommandHandler : IRequestHandler<GoodsvendoradditiveUpdateCommand, APIResult<int>>
    {
        private readonly IBaseRepository<Goodsvendoradditive> _cultivationrepository;
        public GoodsvendoradditiveUpdateCommandHandler(IBaseRepository<Goodsvendoradditive> cultivationrepository)
        {
            _cultivationrepository = cultivationrepository;
        }
        public async Task<APIResult<int>> Handle(GoodsvendoradditiveUpdateCommand request, CancellationToken cancellationToken)
        {
            APIResult<int> result = new APIResult<int>();
            try
            {
                var list = await _cultivationrepository.GetValues(x => x.Id == request.Id);

                list.GoodsvendorProductionbatches = request.GoodsvendorProductionbatches;
                list.GoodsId = request.GoodsId;

                result.Code = ApiEnum.Success;
                result.Msg = "添加剂信息修改成功";
                result.Data = await _cultivationrepository.UpdateAsync(list);
                return await Task.FromResult(result);
            }
            catch (Exception)
            {
                result.Code = ApiEnum.Fail;
                result.Msg = "添加剂信息修改失败";
                return await Task.FromResult(result);
                throw;
            }
        }
    }
}
